﻿<Window x:Class="MContracts.Controls.Dialogs.ClosingStagesWizzard"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Dialogs="clr-namespace:MContracts.Controls.Dialogs" 
        xmlns:converters="clr-namespace:MContracts.Classes.Converters" 
        Title="Мастер закрытия этапов актами" Height="600" Width="800">
    
    <Window.Resources>

        <converters:DateTimeToShortDateConverter x:Key="DateTimeToShortDateConverter"/>
        <converters:StageConditionConverter x:Key="StageConditionConverter"/>
        <converters:StageConditionToImageConverter x:Key="StageConditionToImageConverter"/>

        <Style TargetType="TabItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <Border>
                            <Grid>
                                <Grid/>
                                <ContentPresenter ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="TextBox">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="12" Margin="2, 0, 0, 0" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="MinWidth" Value="200"/>
            <Setter Property="Margin" Value="5"/>
        </Style>

        <Style TargetType="ComboBox">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="12" Margin="2, 0, 0, 0" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="MinWidth" Value="200"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Height" Value="24"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>

        <Style TargetType="DatePicker">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value >
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="18" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="MinWidth" Value="200"/>
            <Setter Property="Margin" Value="5"/>
        </Style>

    </Window.Resources>

    <Grid>
        
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        
        <TabControl x:Name="Wizzard" SelectionChanged="Wizzard_SelectionChanged">
            <TabControl.Items>
                
                <TabItem x:Name="StagesTabItem" >

                    <ScrollViewer>

                        <StackPanel>
                            <TextBlock Text="Отметьте этапы, которые необходимо закрыть" FontSize="14" Margin="3"/>
                            <DockPanel LastChildFill="True">
                                <StackPanel DockPanel.Dock="Left" Width="1"/>
                                <StackPanel DockPanel.Dock="Right" Width="1"/>

                                <DataGrid CanUserAddRows="False" SelectionMode="Single" SelectionUnit="FullRow"
                              HorizontalScrollBarVisibility="Disabled" Margin="3" ItemsSource="{Binding Path=Stages}" CanUserSortColumns="False"
                              HeadersVisibility="Column" AutoGenerateColumns="False" x:Name="StagesDataGrid">
                                    <DataGrid.Columns>

                                        <DataGridTemplateColumn Width="Auto">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <CheckBox Loaded="CheckBox_Loaded" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Margin="2"/>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="№" Width="Auto">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Label Content="{Binding Num}"/>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Width="Auto">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="20" Height="20" Margin="2" ToolTip="{Binding Path=Stagecondition, Converter={StaticResource StageConditionConverter}}" Source="{Binding Path=Stagecondition, Converter={StaticResource StageConditionToImageConverter}}"/>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="Содержание этапа" Width="6*">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <DockPanel LastChildFill="True">
                                                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                        <TextBlock Margin="2" Text="{Binding Path=Subject}" TextWrapping="WrapWithOverflow"/>
                                                    </DockPanel>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="Начало" Width="2*">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <DockPanel LastChildFill="True">
                                                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                        <TextBlock Margin="2" Text="{Binding Path=Startsat, Converter={StaticResource DateTimeToShortDateConverter}}" TextWrapping="WrapWithOverflow"/>
                                                    </DockPanel>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="Окончание" Width="2*">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <DockPanel LastChildFill="True">
                                                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                        <TextBlock Margin="2" Text="{Binding Path=Endsat, Converter={StaticResource DateTimeToShortDateConverter}}" TextWrapping="WrapWithOverflow"/>
                                                    </DockPanel>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="Цена без НДС" Width="2*" x:Name="StageSumColumn">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <DockPanel LastChildFill="True">
                                                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                        <TextBlock Margin="2" Text="{Binding Path=Price}" TextWrapping="WrapWithOverflow"/>
                                                    </DockPanel>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="НДС" Width="2*">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <DockPanel LastChildFill="True">
                                                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                        <TextBlock Margin="2" Text="{Binding Path=Ndsalgorithm}" TextWrapping="WrapWithOverflow"/>
                                                    </DockPanel>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTemplateColumn Header="Ставка НДС" Width="2*">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <DockPanel LastChildFill="True">
                                                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                        <TextBlock Margin="2" Text="{Binding Path=Nds}" TextWrapping="WrapWithOverflow"/>
                                                    </DockPanel>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

                                        <DataGridTextColumn Header="НДС" Width="*" Binding="{Binding PriceNds, StringFormat=N, Mode=OneWay}"/>
                                        <DataGridTextColumn Header="Цена c НДС" Width="2*" Binding="{Binding PriceWithNds, StringFormat=N, Mode=OneWay}"/>

                                    </DataGrid.Columns>
                                </DataGrid>

                            </DockPanel>
                        </StackPanel>

                    </ScrollViewer>
                </TabItem>
                
                <TabItem>
                    <StackPanel>
                        <TextBlock Text="Выберете необходимое действие" FontSize="14" Margin="3" FontWeight="Bold"/>
                        <StackPanel Orientation="Vertical" Margin="10, 3, 3, 3">
                            <RadioButton Content="Выбрать существующий акт" GroupName="1" FontSize="14" Margin="3, 0, 0, 0" Checked="RadioButton_Checked"/>
                            <ComboBox Visibility="Collapsed" ItemsSource="{Binding Acts}" SelectionChanged="ActsComboBox_SelectionChanged"  SelectedItem="{Binding ExistingAct}" x:Name="ActsComboBox"/>
                        </StackPanel>
                        <RadioButton Content="Создать новый акт" GroupName="1" FontSize="14" Margin="13, 3, 3, 3" Checked="RadioButton_Checked_1"/>
                        <RadioButton Content="Открепить от акта" GroupName="1" FontSize="14" Margin="13, 3, 3, 3" Checked="RadioButton_Checked_2"/>
                    </StackPanel>
                </TabItem>

                <TabItem>

                    <StackPanel>
                        <TextBlock Text="Введите данные по акту:" FontSize="14" Margin="3, 3, 3, 10" FontWeight="Bold"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <TextBlock Text="№ акта" Grid.Row="0"/>
                            <TextBox Text="{Binding Path=NewAct.Num, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="0"/>

                            <TextBlock Text="Дата акта" Grid.Row="1"/>
                            <DatePicker SelectedDate="{Binding Path=NewAct.Signdate, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="1"/>

                            <TextBlock Text="НДС" Grid.Row="2"/>
                            <ComboBox ItemsSource="{Binding Ndses, Mode=OneTime}" SelectedItem="{Binding Path=NewAct.Nds, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2"/>

                            <TextBlock Text="Стоимость без НДС" Grid.Row="3"/>
                            <TextBox Text="{Binding NewAct.ActMoney.Factor.National.PricePure, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="3"/>

                            <TextBlock Text="Стоимость с НДС" Grid.Row="4"/>
                            <TextBox IsReadOnly="True" Text="{Binding Path=NewAct.ActMoney.Factor.National.PriceWithNds, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="4"/>

                            <TextBlock Text="Сумма НДС" Grid.Row="5"/>
                            <TextBox IsReadOnly="True" Text="{Binding Path=NewAct.ActMoney.Factor.National.PriceNds, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="5"/>

                            <TextBlock Text="Основание для Промгаза" Grid.Row="6"/>
                            <ComboBox ItemsSource="{Binding Enterpriseauthorities, Mode=OneTime}" SelectedItem="{Binding NewAct.Enterpriseauthority, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="6"/>

                            <TextBlock Text="Регион" Grid.Row="7"/>
                            <ComboBox ItemsSource="{Binding Regions, Mode=OneTime}" SelectedItem="{Binding NewAct.Region, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="7"/>

                            <TextBlock Text="Тип акта" Grid.Row="8"/>
                            <ComboBox ItemsSource="{Binding Acttypes, Mode=OneTime}" SelectedItem="{Binding NewAct.Acttype, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="8"/>

                            <TextBlock Text="Аванс" Grid.Row="9"/>
                            <TextBox Text="{Binding Path=NewAct.TotalSum, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="9"/>

                            <TextBlock Text="Сумма к перечислению" Grid.Row="10"/>
                            <TextBox Text="{Binding Path=NewAct.Sumfortransfer, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="1" Grid.Row="10"/>

                        </Grid>

                    </StackPanel>
                </TabItem>

            </TabControl.Items>
        </TabControl>

        <DockPanel Grid.Row="1">
            <Dialogs:TabControlMover x:Name="Mover" DockPanel.Dock="Right"/>
        </DockPanel> 
        
    </Grid>
</Window>
